package com.ticket.util;

import java.util.List;

/**
 * @author 23623
 * @version 8.0
 * @description TODO  封装分页参数
 * @date 2023/8/22
 * @updatDate 2023/09/05
 */
public class Page<T> {

    private int totalPageCount=0;           //总页数
    private int pageSize=5;                 //每页展示记录数
    private int totalCount;                 //总条数
    private int currPageNo=1;                 //当前页数
    private List<T> dataList;               //分页的数据
    private int startIndex;                 //查询起始位置

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        if(totalCount>0){
            this.totalCount = totalCount;
            this.totalPageCount=this.totalCount%pageSize==0?
                    this.totalCount/pageSize:(this.totalCount/pageSize)+1;
        }
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
        //根据当前页数和页面显示条数获取查询起始位置
        this.startIndex = (currPageNo-1) * this.pageSize;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    /**
    * @author GongHongLi 
    * @description TODO servlet使用的构造器
    * @date 2023/9/5 14:44
     * @param pageSize 页面显示条数
     * @param currPageNo   当前页数
    */
    public Page(int pageSize, int currPageNo) {
        this.pageSize = pageSize;
        this.currPageNo = currPageNo;
        //根据当前页数和页面显示条数获取查询起始位置
        this.startIndex = (currPageNo-1) * pageSize;
    }

    /**
    * @author GongHongLi
    * @description TODO dao层使用的构造函数
    * @date 2023/9/5 14:57
     * @param totalCount 总条数
     * @param dataList 分页的数据
    * @return
    */
    public Page(int totalCount, List<T> dataList) {
        this.setTotalCount(totalCount);
        this.dataList = dataList;
    }

    public Page() {
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    @Override
    public String toString() {
        return "Page{" +
                "totalPageCount=" + totalPageCount +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", currPageNo=" + currPageNo +
                ", dataList=" + dataList +
                ", startIndex=" + startIndex +
                '}';
    }
}
